"""
   author: 陈亚敏
   data: 2021/11/24  15:13
   project: 1
"""
import requests
import json
import time
str1=''
with open('scwebsite2_ssl.log','r') as fp:
    for i in fp.readlines():
        for j in i:

            if j !='"' :
                str1+=j
            else:
                break
list1=list(str1.split())
# print(list1)
san=3
shijian=[]
for i in list1:
    shijian+=list1[san].split()
    san+=5
    if san>len(list1)-1:
        break
for i in shijian:
    i1=i.strip('[')#04/Jun/2021:16:55:33
    hms=i1.split(':',1)[1]
    ymd=i1.replace('Jun','7').split(':',1)[0]
    print(f"{ymd.split('/',2)[2]}-{ymd.split('/',2)[1]}-{ymd.split('/',2)[0]} {i1.split(':',1)[1]}")


k=0
list2=[]
for i in list1:
    list2+=list1[k].split()
    k+=5
    if k>len(list1)-1:
        break
try:
    set1=set(list2)
    for i in set1:
        url = f"http://ip.aliyun.com/outGetIpInfo?accessKey=alibaba-inc&ip={i}"
        response = requests.get(url)

        with open ('reault.txt','a+',encoding='utf-8') as fp:
            fp.write(f"{json.loads(response.text)}\n")

except ConnectionError:
    print("连接错误！")

